package com.example.constellation.luckfrag;

import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.GridView;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.constellation.R;
import com.example.constellation.bean.StarInfoBean;

import java.util.List;


/**
 * 星座运势
 */
public class LuckFragment extends Fragment {
    GridView luckGv;
    List<StarInfoBean.StarinfoBean> mDatas;
    LuckBaseAdapter lba;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.fragment_luck, container, false);
        luckGv=view.findViewById(R.id.luckfrag_gv);
        //获取数据
        Bundle bundle=getArguments();
        StarInfoBean info=(StarInfoBean) bundle.getSerializable("info");
        mDatas=info.getStarinfo();
        //创建适配器对象
        lba=new LuckBaseAdapter(getContext(),mDatas);
        //设置适配器
        luckGv.setAdapter(lba);
        //设置GridView每一项的监听事件
        luckGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                StarInfoBean.StarinfoBean bean=mDatas.get(i);
                String name=bean.getName();
                Intent intent=new Intent(getContext(),LuckAnalysisActivity.class);
                intent.putExtra("name",name);//将name放在intent中传到另一个页面中
                startActivity(intent);
            }
        });
        return view;
    }
}
